import com.sun.org.apache.xpath.internal.operations.Operation;

import java.util.LinkedList;
import java.util.Objects;
import java.util.Stack;

public class Test {
    //逆波兰表达式求值
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();

        for (int i = 0; i < tokens.length; i++) {
            if(!tokens[i].equals("+")
                    && !tokens[i].equals("-")
                    && !tokens[i].equals("*")
                    && !tokens[i].equals("/")) {
                stack.add(Integer.parseInt(tokens[i]));
            }else {
                int p1=stack.pop();
                int p2=stack.pop();
                switch (tokens[i]) {
                    case "+":
                        stack.add(p2+p1);
                        break;
                    case "-":
                        stack.add(p2-p1);
                        break;
                    case "*":
                        stack.add(p2*p1);
                        break;
                    case "/":
                        stack.add(p2/p1);
                        break;
                }
            }

        }
        return stack.pop();
    }

}
